class Solution {
public:
    static bool wrong;
    int StrToInt(string str) {
        if(str.empty())
        {
            wrong = true;
            return 0;
        }
        int length = str.size();
        if(str[0] == '-')
            return -readNumbers(str,1,length-1);
        else if(str[0] == '+')
            return readNumbers(str,1,length-1);
        else if(str[0] >= '0' && str[0] <= '9')
            return readNumbers(str,0,length-1);
        else
        {
            wrong = true;
            return 0;
        }
    }
    int readNumbers(const string &str,int idxbg,int idxed)
    {
        if(idxbg > idxed)
        {
            wrong = true;
            return 0;
        }
        int sum = 0, bit = 1;
        for(int idx = idxed; idx >= idxbg;--idx)
        {
            if(str[idx] >= '0' && str[idx] <= '9')
            {
                sum+=(str[idx] - '0')*bit;
                bit*=10;
            }
            else
            {
                wrong = true;
                return 0;
            }
        }
        return sum;
    }
};
bool Solution::wrong = false;